/* Copyright (c) 2009 SpringShowcase, Inc.
 * All right reserved.
 * http://code.google.com/p/springshowcase/
 * This software is the confidential and proprietary information of BeyondWeb
 * , Inc. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement
 * you entered into with BeyondWeb.
 *
 * Revision History
 * Author              Date             Description
 * ------------------   --------------    ------------------
 *  kwondohee           2010. 4. 8.        
 */
package org.springshowcase.rpc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO: Auto-generated Javadoc
/**
 * The Class DwrRepositoryImpl.
 */
public class DwrRepositoryImpl implements DwrRepository {

	// ---------------------------------------------------------------------
	// Class Variable Declaration
	// ---------------------------------------------------------------------
	/** The Constant logger. */
	private static final Logger logger = LoggerFactory
			.getLogger(DwrRepositoryImpl.class);

	/** The all users. */
	private static Map<String, User> allUsers = new HashMap<String, User>();

	// ---------------------------------------------------------------------
	// Constructor Method Declaration
	// ---------------------------------------------------------------------
	// ---------------------------------------------------------------------
	// DI Method (setter,getter) Declaration
	// ---------------------------------------------------------------------
	// ---------------------------------------------------------------------
	// this Method (public/private) Declaration
	// ---------------------------------------------------------------------
	// ---------------------------------------------------------------------
	// interface implement Method (public/private) Declaration
	// ---------------------------------------------------------------------

	/* (non-Javadoc)
	 * @see org.springshowcase.rpc.DwrRepository#insertUser(org.springshowcase.rpc.User)
	 */
	@Override
	public void insertUser(User user) {
		allUsers.put(user.getId(), user);
	}

	/* (non-Javadoc)
	 * @see org.springshowcase.rpc.DwrRepository#selectUser(org.springshowcase.rpc.User)
	 */
	@Override
	public User selectUser(User user) {
		User returnUser = (User) allUsers.get(user.getId());
		return returnUser;
	}

	/* (non-Javadoc)
	 * @see org.springshowcase.rpc.DwrRepository#selectUserList()
	 */
	@Override
	public List<User> selectUserList() {
		java.util.Set keyset = allUsers.keySet();
		Object[] hashkeys = keyset.toArray();
		List<User> list = new ArrayList<User>();
		for (int i = 0; i < hashkeys.length; i++) {
			String key = (String) hashkeys[i];
			User user = (User)allUsers.get(key);
			if(user!=null) {
				list.add(user);
			}
		}
		return list;
	}
	
	
	/* (non-Javadoc)
	 * @see org.springshowcase.rpc.DwrRepository#exceptionUser()
	 */
	@Override
	public void exceptionUser() {
		String str = null;
		str.indexOf(".");
	}


	static {
		allUsers.put("id1", new User("id1", "dw1", "springorg@gmail.com"));
		allUsers.put("id2", new User("id2", "dw2", "springorg@gmail.com"));
		allUsers.put("id3", new User("id3", "dw3", "springorg@gmail.com"));
	}

	// ---------------------------------------------------------------------
	// abstract implement Method (public/private) Declaration
	// ---------------------------------------------------------------------

	// ---------------------------------------------------------------------
	// abstract Method (public/private) Declaration
	// ---------------------------------------------------------------------
}
